#include "gates.h"
#include "bit_def.h"

/*
 * Bit and(Bit a, Bit b);
 * Performs a boolean AND operation and returns the result.
 * a: the first operand
 * b: the second operand
 */
Bit and(Bit a, Bit b)
{
    Bit r;

    a = maskBit(a);    // make sure no spurious bits get by!
    b = maskBit(b);
    r = maskBit(a & b);

    return r;
}

/*
 * Bit not(Bit a);
 * Performs a boolean NOT operation and returns the result.
 * a: the operand
 */
Bit not(Bit a)
{
    Bit r;

    a = maskBit(a);    // make sure no spurious bits get by!
    r = maskBit(~a);

    return r;
}

/*
 * Bit or(Bit a, Bit b);
 * Performs a boolean OR operation and returns the result.
 * a: the first operand
 * b: the second operand
 */
Bit or(Bit a, Bit b)
{
    Bit r;

    a = maskBit(a);    // make sure no spurious Bits get by!
    b = maskBit(b);
    r = maskBit(a | b);

    return r;
}

/*
 * Bit xor(Bit a, Bit b);
 * Performs a boolean XOR operation and returns the result.
 * a: the first operand
 * b: the second operand
 */
Bit xor(Bit a, Bit b)
{
    Bit r;

    a = maskBit(a);    // make sure no spurious Bits get by!
    b = maskBit(b);
    r = maskBit(a ^ b);

    return r;
}
